'''
Function:
    用来读取txt文件
author:
    walker
time:
    2020/5/12
'''

class read_file():
    def __init__(self,txt_path):
        self.info = "read game level"
        self.txt_path = txt_path

    '''读取txt文件'''
    def read_txt(self):
        content_list = []
        with open(self.txt_path,'r') as f:
            content = f.read().splitlines()
            for content_line in content:
                line = content_line.split(',')
                for i in range(len(line)):
                    if line[i] == "''":
                        line[i] = '0'
                content_list.append(line)
        f.close()
        # for content_list_item in content_list:
            # print(content_list_item)
        return content_list

    '''获取到元素的位置'''
    def cal_each_roles_pos(self):
        content_list = self.read_txt()
        walls = []
        non = []
        start = []
        ending = []
        trans_one = []
        trans_two = []
        water = []
        fire = []
        lists = []
        for i in range(len(content_list)):
            for j in range(len(content_list[0])):
                if content_list[i][j] == '*':
                    walls.append([i,j])
                elif content_list[i][j] == '0':
                    non.append([i,j])
                elif content_list[i][j] == '1':
                    trans_one.append([i,j])
                elif content_list[i][j] == '2':
                    trans_two.append([i,j])
                elif content_list[i][j] == 'W':
                    water.append([i,j])
                elif content_list[i][j] == 'F':
                    fire.append([i,j])
                elif content_list[i][j] == 'X':
                    start.append([i,j])
                elif content_list[i][j] == 'Y':
                    ending.append([i,j])
        lists.append(walls)
        lists.append(non)
        lists.append(start)
        lists.append(ending)
        lists.append(trans_one + trans_two)
        lists.append(water)
        lists.append(fire)
        return lists
